
// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "editor.h"
#include "ChildView.h"
#include "MapManager.h"
#include "maptile.h"
#include "inputmanager.h"
#include "gamemanager.h"
#include "EditMaptileDlg.h"
#include "TerrainDialog.h"
#include "EditorMouseHandler.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView, CWnd)
	ON_WM_PAINT()
    ON_WM_LBUTTONDOWN()
    ON_WM_SIZE()
    ON_WM_MOVE()
END_MESSAGE_MAP()



// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CWnd::OnPaint() for painting messages
}

void CChildView::OnLButtonDown( UINT nFlags, CPoint point )
{
    if( g_pEditorMouseHandler )
    {
        g_pEditorMouseHandler->Do();
        return;
    }
    const InputInfo &info = CInputManager::Instance().GetInputInfo();
    POINT gamemousepos = {info.GameMouse.x+gc.screenrect.x1, info.GameMouse.y+gc.screenrect.y1};

    CMapTile * tile = CMapManager::Instance().GetClickedTile(gamemousepos);
    if( tile )
	{
		CEditMaptileDlg dlg;
		dlg.SetMaptile( tile );
		dlg.DoModal();
	}
}

void CChildView::OnSize( UINT nType, int cx, int cy )
{
    RECT rect;
    ::GetClientRect(CD3DManager::Instance().GetHwnd(), &rect); 
    gc.windowsrect = rect;
    return CWnd::OnSize(nType, cx, cy );
}

void CChildView::OnMove( int x, int y )
{
    RECT rect;
    ::GetClientRect(CD3DManager::Instance().GetHwnd(), &rect); 
    gc.windowsrect = rect;
    return CWnd::OnMove(x, y);
}
